package app;

import java.io.BufferedReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import util.file.LineFilter;
import util.file.LineReader;
import util.file.LineWriter;

public class Arp {
	
	String inputPath;
	String outputPath;
	String line;
	String save = "";
	String[] arp;
	
	public Map<String, String> getArp(String location) {
		
		Map<String, String> arpMap = new HashMap<String, String>();
		inputPath = "/home/cryptdb/temp/" + location + 
					"/app/addrs.txt";
		outputPath = "/home/cryptdb/temp/" + location +
					"/app/filter addrs";
		LineFilter filter = new LineFilter();
		LineReader lineReader = new LineReader(inputPath);
		LineWriter lineWriter = new LineWriter(outputPath);
		
		
		BufferedReader bufferedReader = lineReader.getBufferedReader();
		
		try {
			while ((line = bufferedReader.readLine()) != null) {
				filter.setLine(line);
				if (!filter.isUseless()) {
					if (filter.isExist()) {
						arp = filter.getArpArray();
						if (!filter.isIp()) {
							arpMap.put(arp[0], arp[1]);
							save += arp[0] + "~" + arp[1] + "\n";
						}
					} else {
						arp = filter.getArpArray1();
						System.out.println(line);
						if (!filter.isIp()) {
							arpMap.put(arp[0], arp[1]);
							save += arp[0] + "~" + arp[1] + "\n";
						}
					}
				}
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		lineWriter.save(save);
		return arpMap;
		
	}

}
